<template>
	<view class="container">
		<u-navbar title='选择' :title-bold='true' :border-bottom='false' :is-fixed='true'></u-navbar>

		<u-search placeholder="搜索名称" @change='search' v-model="keyword" :animation="true"></u-search>
		<view class="u-flex u-row-between u-m-t-20 u-m-b-20">
			<u-field label-width='80' v-model="oth.title" label="其他 :" />
			<u-button @click='sure' type="success" size="mini">确定</u-button>
		</view>

		<!-- <u-index-list :scrollTop="scrollTop" :indexList="indexList"> -->
		<!-- <view v-for="(item, index) in indexList" :key="index"> -->
		<!-- <u-index-anchor :custom-style="{'background-color': '#FFF',margin: '10rpx 0'}" :index="item" /> -->
		<view v-for="(itm,idx) in list" :key="idx">
			<view class="list-cell" @click="check(itm)">
				{{itm.title}}
			</view>
			<u-line v-if="idx!=item.length-1" />
		</view>
		<!-- </view> -->
		<!-- </u-index-list> -->
		<!-- 提示 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		selectdrug
	} from '../../api/index.js'
	export default {
		data() {
			return {
				keyword: '',
				scrollTop: 0,
				indexList: ["A", "B"],
				list: [],
				page: [],
				oth: {
					id: 20
				}
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onLoad(e) {
			this.page = getCurrentPages()
			this.init()

		},

		methods: {
			init() {
				let that = this
				selectdrug().then(res => {
					if (res.code == 1) {
						that.list = res.data.list
						that.$store.state.drug = that.list
					} else {
						that.$refs.uToast.show({
							title: res.msg
						})
					}
				})
			},
			search() {
				this.list = this.$store.state.drug
				if (this.keyword) {
					let arr = []
					this.list.forEach(item => {
						if (item.title.indexOf(this.keyword) != -1) {
							arr.push(item)
						}
					})
					this.list = arr
				}

			},
			sure(e) {
				let prevpage = this.page[this.page.length - 2]
				prevpage.$vm.medication(this.oth)
				uni.navigateBack({
					delta: 1
				})
			},
			check(itm) {
				let prevpage = this.page[this.page.length - 2]
				prevpage.$vm.medication(itm)
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.container {
		min-height: 100vh;
		background-color: #FFF;
		padding: 20rpx 30rpx;
	}

	u-field {
		width: 100%;
	}

	.list-cell {
		display: flex;
		align-items: center;
		box-sizing: border-box;
		width: 100%;
		padding: 10px 24rpx;
		overflow: hidden;
		color: #323233;
		font-size: 14px;
		line-height: 24px;
		background-color: #fff;
	}
</style>